import React from 'react';
import { getOverviewWorkData } from '@/services/organization';

const useList = type => {
    const [data, setData] = React.useState([]);
    const [loading, setLoading] = React.useState(true);

    const fetchData = async () => {
        setLoading(true);

        const { data: rawData = {}, code } = (await getOverviewWorkData({ type })) || {};

        if (code === 10000) {
            setData(rawData);
        }

        setLoading(false);
    };

    React.useEffect(() => {
        fetchData();
    }, [type]);

    return [loading, data];
};

export default useList;
